package com.googlecode.marrowboy.junit;

import org.junit.runner.Description;
import org.junit.runner.Result;
import org.junit.runner.notification.Failure;
import org.junit.runner.notification.RunListener;

/**
 * JUnit4 {@link RunListener} which hooks into MarrowBoy.
 * 
 * @author mjg
 */
public class JUnit4RunListener extends RunListener {

    public JUnit4RunListener() {
        System.out.println("JUnit4RunListener.JUnit4RunListener()");
    }

    @Override
    public void testAssumptionFailure(Failure failure) {
        System.out.println("JUnit4RunListener.testAssumptionFailure()");
        dumpDescription(failure.getDescription());
    }

    @Override
    public void testFailure(Failure failure) throws Exception {
        System.out.println("JUnit4RunListener.testFailure()");
        dumpDescription(failure.getDescription());
    }

    @Override
    public void testFinished(Description description) throws Exception {
        System.out.println("JUnit4RunListener.testFinished()");
        dumpDescription(description);
    }

    @Override
    public void testIgnored(Description description) throws Exception {
        System.out.println("JUnit4RunListener.testIgnored()");
        dumpDescription(description);
    }

    @Override
    public void testRunFinished(Result result) throws Exception {
        System.out.println("JUnit4RunListener.testRunFinished()");
    }

    @Override
    public void testRunStarted(Description description) throws Exception {
        System.out.println("JUnit4RunListener.testRunStarted()");
        dumpDescription(description);
    }

    @Override
    public void testStarted(Description description) throws Exception {
        System.out.println("JUnit4RunListener.testStarted()");
        dumpDescription(description);
    }

    private void dumpDescription(Description description) {
        System.out.println("  d: " + description);
    }

}
